<?php 

namespace Admin\Logic;

class Admin_itemLogic{

	const PUT_AWAY = 1;  //商品上架
    const SOLD_OUT = 2;  //商品下架
    const DELETE_OUT = 0; //商品删除
	
	public function __construct() {
		//var_dump(1);exit;
        $this->item = D('Admin_item');
        $this->image = D('Admin_item_image');
        $this->type = D('admin_item_type');
        //import('Memcachectr');
        //$this->m = \Think\Memcachectr::create();
    }

	public function getItems($page,$limit=20){
		$total_page = ceil($this->countTotal()/$limit);
        $total_page = $total_page>0?$total_page:1;
        $page = $page>0?$page:1;
        $page = $page>$total_page?$total_page:$page;
        $list = $this->item->order('id desc')->limit(($page-1)*$limit,$limit)->select();
        $_Page  = new \Think\Page($total_page*$limit,$limit);
        $show  = $_Page->show();
        $show = str_replace('/index.php/','/',$show);
        return array('page'=>$show,'list'=>$list);
	}

	/*获取总数量*/
    public function countTotal(){
        return $this->item->where('status!=0')->count();
    }

	public function item_image($item_number){
		return $this->image->where('item_number='.$item_number.' and status=1')->select();
	}

	//商品分类
	public function type(){
		return $this->type->select();
	}




}	